# $Id: PKGBUILD 240297 2015-06-03 10:22:03Z fyan $
# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Andrea Scarpino <andrea@archlinux.org>

pkgname=qt5-declarative
_qtver=5.9.1
pkgver=${_qtver/-/}
pkgrel=5
arch=('i686' 'x86_64')
url='http://qt-project.org/'
license=('GPL3' 'LGPL3' 'FDL' 'custom')
pkgdesc='Classes for QML and JavaScript languages'
depends=('qt5-xmlpatterns')
makedepends=('python2' 'cmake')
groups=('qt' 'qt5')
conflicts=('qtchooser' 'qt5-declarative-render2d')
replaces=('qt5-declarative-render2d')
_pkgfqn="${pkgname/5-/}-opensource-src-${_qtver}"
source=("http://download.qt.io/official_releases/qt/${pkgver%.*}/${_qtver}/submodules/${_pkgfqn}.tar.xz"
        qtbug-61681.patch::"https://github.com/qt/qtdeclarative/commit/ab5d4c78.patch" qtbug-61754.patch)
sha256sums=('d2fe6c9c1a9f19af6e96553c6d75366ab8f397bc232acd67d31476955fee94ff'
            '0d8f1e91b221da8727618b81f3a6b80566095d1afe442f198a6ef29cdfb58898'
            '6b4a77535275a6358f61d44b6f740cb85729992582f3b5669ac3b1ed1fdb4e05')

prepare() {
  mkdir -p build

  # Use python2 for Python 2.x
  find -name '*.pro' -o -name '*.pri' | xargs sed -i -e 's|python -c|python2 -c|g' -e 's|python \$|python2 \$|g'

  cd ${_pkgfqn}
  patch -p1 -i ../qtbug-61681.patch # https://bugreports.qt.io/browse/QTBUG-61681
  patch -p1 -i ../qtbug-61754.patch # fix memory leak with threaded renderer
}

build() {
  cd build

  export PYTHON=python2
  qmake ../${_pkgfqn}
  make
}

package() {
  cd build
  make INSTALL_ROOT="$pkgdir" install

  # Symlinks for backwards compatibility
  for b in "$pkgdir"/usr/bin/*; do
    ln -s /usr/bin/$(basename $b) "$pkgdir"/usr/bin/$(basename $b)-qt5
  done

  # Drop QMAKE_PRL_BUILD_DIR because reference the build dir
  find "$pkgdir/usr/lib" -type f -name '*.prl' \
    -exec sed -i -e '/^QMAKE_PRL_BUILD_DIR/d' {} \;

  install -d "$pkgdir"/usr/share/licenses
  ln -s /usr/share/licenses/qt5-base "$pkgdir"/usr/share/licenses/${pkgname}
}
